package net.hn.hnms.biz.project.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.project.domain.LegalPerson;
import net.hn.hnms.biz.project.request.LegalPersonReq;
import net.hn.hnms.biz.project.service.LegalPersonService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "法人信息", tags = {"法人信息"})
@RestController
@RequestMapping("/legal/person")
public class LegalPersonController extends BaseController{

    @Autowired
    private LegalPersonService egalPersonService;
    /**
     * 新增法人信息
     */
    @ApiOperation("新增法人信息")
    @SaCheckPermission("legal:person:add")
    @PostMapping("/add")
    @Log(title = "新增法人信息", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody LegalPersonReq legalPersonReq) {
        return toAjax(egalPersonService.insert(legalPersonReq));
    }

    /**
     * 删除法人信息
     */
    @ApiOperation("删除法人信息")
    @SaCheckPermission("legal:person:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @PostMapping("delete")
    @Log(title = "删除法人信息", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        egalPersonService.updateDeleteByIds(idList);
        return R.ok();
    }

    /**
     * 更新法人信息
     */
    @ApiOperation("更新法人信息")
    @SaCheckPermission("legal:person:update")
    @PostMapping("/update")
    @Log(title = "更新法人信息", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody LegalPersonReq legalPersonReq) {
        egalPersonService.updateById(legalPersonReq);
        return R.ok();
    }

    /**
     * 法人信息详情
     */
    @ApiOperation("法人信息详情")
    @GetMapping("/{id}")
    public R<LegalPerson> detail(@PathVariable("id") String id) {
        return R.ok(egalPersonService.selectDetailById(id));
    }


    /**
     * 法人信息列表
     */
    @ApiOperation("法人信息列表")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<LegalPerson>> page(LegalPersonReq legalPersonReq, PageQuery pageQuery) {
        return R.ok(egalPersonService.selectPageList(legalPersonReq, pageQuery));
    }




}
